﻿<navigation:Page xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input"  
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:dataFormToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit" 
                 xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input" 
                 xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
                 xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
                 x:Class="MusicStore.Silverlight.Views.Album"
         xmlns:converters="clr-namespace:MusicStore.Silverlight.Converters"                        
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Album Page">
   <controlsToolkit:BusyIndicator IsBusy="{Binding IsBusy}">
      <Grid x:Name="LayoutRoot">
         <Grid.Resources>
            <converters:UploadImageEnableConverter x:Key="UploadEnabler" />
         </Grid.Resources>
         <Grid.RowDefinitions>
            <RowDefinition Height="80"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="160"/>
            <ColumnDefinition/>
         </Grid.ColumnDefinitions>
         <TextBlock Margin="40,16" Grid.ColumnSpan="2" Text="{Binding Text, ElementName=TextAlbumTitle, Mode=OneWay}" FontSize="26.667" TextAlignment="Center" />
         <Grid Margin="0" Grid.Row="1">
            <Grid.RowDefinitions>
               <RowDefinition Height="0.5*"/>
               <RowDefinition Height="0.5*"/>
            </Grid.RowDefinitions>
            <Border Margin="8,8,0,0" Height="136" HorizontalAlignment="Left" VerticalAlignment="Top" Width="136" d:LayoutOverrides="Width, Height">
               <Border.Effect>
                  <DropShadowEffect BlurRadius="100" ShadowDepth="0" Opacity="1" Color="#FFFFFF" />
               </Border.Effect>
               <Image x:Name="ImgPreview" Source="{Binding Album.Image}" />
            </Border>
            <Button x:Name="BtnUploadPreview" Click="BtnUploadPreview_Click" IsEnabled="{Binding Path=Album.Id, Converter={StaticResource UploadEnabler}}" Margin="8,160,16,0" Content="Upload" VerticalAlignment="Top"/>
            <Button x:Name="BtnCancel" Click="BtnCancel_Click" Margin="8,0,16,16" Content="Cancel" Grid.Row="1" Height="24" VerticalAlignment="Bottom"/>
            <Button x:Name="BtnDelete" Click="BtnDelete_Click"  Height="24" Margin="8,0,16,56" VerticalAlignment="Bottom" Content="Delete" Grid.Row="1"/>
            <Button x:Name="BtnSave" Click="BtnSave_Click" Margin="8,0,16,96" Content="Save" Grid.Row="1" Height="24" VerticalAlignment="Bottom"/>
         </Grid>
         <StackPanel Grid.Column="1" Grid.Row="1">
            <dataFormToolkit:DataField Label="Title" >
               <TextBox x:Name="TextAlbumTitle" Text="{Binding Album.ValidatableTitle, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" Margin="32,0,5,0" />
            </dataFormToolkit:DataField>
            <dataFormToolkit:DataField Label="Author" >
               <input:AutoCompleteBox x:Name="TextAuthor" Text="{Binding Album.Author, Mode=TwoWay}" Margin="20,0,3,0" />
            </dataFormToolkit:DataField>
            <dataFormToolkit:DataField Label="Label" VerticalAlignment="Top">
               <input:AutoCompleteBox x:Name="TextLabel" Text="{Binding Album.Label, Mode=TwoWay}" Margin="28,0,3,0" />
            </dataFormToolkit:DataField>
            <dataFormToolkit:DataField Label="Genre" VerticalAlignment="Top" >
               <ComboBox ItemsSource="{Binding Genres}" SelectedItem="{Binding Album.Genre, Mode=TwoWay}" Margin="26,0,3,0" />
               <!--<input:AutoCompleteBox Style="{StaticResource EditableComboStyle}" ItemsSource="{Binding Genres}" x:Name="TextGenre" Text="{Binding Album.Genre, Mode=TwoWay}" Margin="28,0,3,0" />-->
            </dataFormToolkit:DataField>
            <dataFormToolkit:DataField Label="Date" VerticalAlignment="Top">
               <!-- we use the datetimeconverter to avoid the cast of a null value to a date and avoid the default invalid cast error message during validation -->
               <controls:DatePicker Style="{StaticResource DatePickerStyle}" x:Name="DpPubblicationDate" SelectedDate="{Binding Album.PublicationDate, Converter={StaticResource DateTimeFormatter}, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True}" Margin="34,0,3,0" />
            </dataFormToolkit:DataField>
         </StackPanel>
         <controls:TabControl Margin="16,184,16,16" Grid.Column="1" Grid.Row="1">
            <controls:TabItem VerticalAlignment="Bottom" Header="Tracks">
               <Grid>
                  <Grid.RowDefinitions>
                     <RowDefinition Height="*"/>
                     <RowDefinition Height="30"/>
                  </Grid.RowDefinitions>
                  <TextBox x:Name="TextNumber" HorizontalAlignment="Left" Margin="8,4,0,4" Width="50" Grid.Row="1" />
                  <TextBox x:Name="TextTitle" Margin="62,4,146,4" Grid.Row="1" />
                  <TextBox x:Name="TextDuration" Margin="0,4,46,4" Grid.Row="1" HorizontalAlignment="Right" Width="96"/>
                  <Button x:Name="BtnAddTrack" Click="BtnAddTrack_Click" HorizontalAlignment="Right" Margin="0,4,8,4" Width="34" Content="Add" Grid.Row="1"/>
                  <data:DataGrid ItemsSource="{Binding Tracks}" AutoGenerateColumns="False" >
                     <data:DataGrid.Columns>
                        <data:DataGridTextColumn IsReadOnly="True" Header="Number" Binding="{Binding Number}" />
                        <data:DataGridTextColumn IsReadOnly="True" Header="Title" Binding="{Binding Title}" />
                        <data:DataGridTextColumn IsReadOnly="True" Header="Duration" Binding="{Binding Duration}" />
                        <data:DataGridTemplateColumn>
                           <data:DataGridTemplateColumn.CellTemplate>
                              <DataTemplate>
                                 <Button Content="X" VerticalAlignment="Center" 
                                Background="Red" Tag="{Binding}" Click="DeleteTrack_Click" />
                              </DataTemplate>
                           </data:DataGridTemplateColumn.CellTemplate>
                        </data:DataGridTemplateColumn>
                     </data:DataGrid.Columns>
                  </data:DataGrid>
               </Grid>
            </controls:TabItem>
            <controls:TabItem Header="Note">
               <Grid>
                  <TextBox Text="{Binding Album.Note, Mode=TwoWay}" Margin="8" HorizontalScrollBarVisibility="Visible" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"/>
               </Grid>
            </controls:TabItem>
         </controls:TabControl>
         <dataInput:ValidationSummary x:Name="AlbumValidationSummary" Margin="10" Grid.Row="2" Grid.ColumnSpan="2"></dataInput:ValidationSummary>
      </Grid>
   </controlsToolkit:BusyIndicator>
</navigation:Page>
